package deibay.server;

import java.util.logging.Level;

import deibay.DeibayLogger;
import deibay.server.network.NetworkManager;
import deibay.users.User;


/**
 * @author   Joel Cordeiro
 */
public class ServerManager {

	private DataManager dataManager = null;	
	private EventManager eventManager = null;
	private NetworkManager networkManager = null;
	private UserManager userManager = null;
	private MessageQueue messageQueue = null;
	
	private static ServerManager instance = null;
	
	/**
	 * @return
	 * @uml.property  name="instance"
	 */
	public static ServerManager getInstance()
	{
		if(instance==null)
			instance = new ServerManager();
		return instance;
	}
	
	private ServerManager()
	{		
		eventManager = new EventManager();
		dataManager = new DataManager();
		userManager = new UserManager();
		messageQueue = new MessageQueue();
		networkManager = new NetworkManager();		
	}		

	public void init()
	{
		eventManager.init();
		dataManager.init();
		userManager.init();
		networkManager.init();	
		messageQueue.init();
	}

	/**
	 * @return
	 * @uml.property  name="userManager"
	 */
	public UserManager getUserManager()
	{
		return this.userManager;
	}
	
	/**
	 * @return
	 * @uml.property  name="dataManager"
	 */
	public DataManager getDataManager()
	{
		return this.dataManager;
	}
	
	/**
	 * @return
	 * @uml.property  name="eventManager"
	 */
	public EventManager getEventManager()
	{
		return this.eventManager;
	}
	
	/**
	 * @return
	 * @uml.property  name="networkManager"
	 */
	public NetworkManager getNetworkManager()
	{
		return this.networkManager;
	}
	
	/**
	 * @return
	 * @uml.property  name="messageQueue"
	 */
	public MessageQueue getMessageQueue()
	{
		return this.messageQueue;
	}
	
	public User authenticate(String login, String password) 
	{		
		return userManager.authenticate(login, password);
	}

	public User register(String login, String password, String email, String address, String role) 
	{
		return userManager.register(login, password, email, address, role);
	}	
	
	public static void main(String args[])
	{
		ServerManager.getInstance().init();
	}
}
